<template>
  <div>
    <div>
<!--      <h3 v-model="date" id="timeStyle">{{// date | formatDate}}</h3>-->
      <h3 v-model="date" id="timeStyle">{{true_date}}</h3>
    </div>
    <el-table
        :data="dash_watcher"
        border
        style="width: 100%">
      <el-table-column
          fixed
          prop="name"
          label="姓名"
          width="150">
      </el-table-column>
      <el-table-column
          prop="email"
          label="邮箱"
          width="200">
      </el-table-column>
      <el-table-column
          prop="position"
          label="岗位"
          width="100">
      </el-table-column>

    </el-table>

<!--    <el-pagination-->
<!--        background-->
<!--        layout="prev, pager, next"-->
<!--        page-size="6"-->
<!--        :total="100"-->
<!--        @current-change="page"-->
<!--    >-->
<!--    </el-pagination>-->
  </div>

</template>

<script>
var padDate = function (value) {
  return value <10 ? '0' + value:value;
};
export default {
  methods: {
    handleClick(row) {
      console.log(row);
    },
    stateFormat(row, column) {
      let i=0;
      let  tabledata = this.tableData
      // let username=this.username;
      return ((JSON.parse(tabledata[i++].watcher))[0]).name;
    },
    page(currentPage){
      const _this=this;
      axios.get('http://localhost:8089/banner/'+currentPage+'/5').then(function (resp){
        alert(currentPage)
        console.log(resp);
        console.log(resp.data[1]);
        console.log(resp.data[1].watcher);
        console.log(JSON.parse(resp.data[1].watcher));
        _this.dash_watcher=JSON.parse(resp.data[1].watcher);
        console.log(((JSON.parse(resp.data[1].watcher))[0]).email);
        console.log(((JSON.parse(resp.data[1].watcher))[0]).name);
        console.log(((JSON.parse(resp.data[1].watcher))[0]).position);
        _this.tableData = resp.data
        _this.username=((JSON.parse(resp.data[0].watcher))[0]).name;
        // _this.total = resp.
  })
    },
    mounted() {
      let _this = this; // 声明一个变量指向Vue实例this，保证作用域一致
      this.timer = setInterval(() => {
        _this.date = new Date(); // 修改数据date
      }, 1000)
    },
    beforeDestroy: function () {
      if (this.timer) {
        clearInterval(this.timer);
      }
    }
  },
  // 程序一运行就会加载
  created(){

    //昨天的时间
    var day = new Date();
    day.setTime(day.getTime()-24*60*60*1000);
    var s1 = day.getFullYear()+"-" + (day.getMonth()+1) + "-" + day.getDate();
    this.date = s1;
    // alert(this.date)

    let week = day.getDay();
    let weeks = ["日","一","二","三","四","五","六"];
    let getWeek = "星期" + weeks[week];
    // alert(getWeek)

    var true_date = s1+'|'+' '  +getWeek
    this.true_date = true_date

    const  _this= this
    // axios.get('http://localhost:8089/banner/1/5').then(function (resp){
    axios.get('http://localhost:8089/find/'+ this.date).then(function (resp){
      console.log(resp)
      _this.tableData = resp.data;
      _this.dash_watcher=JSON.parse(resp.data.watcher);//返回来的5条数据取一条
      console.log(_this.dash_watcher)
      console.log(resp)
      console.log(resp.data)
      console.log(((JSON.parse(resp.data.watcher))[0]).name);
      _this.username=((JSON.parse(resp.data.watcher))[0]).name;
      // _this.total = resp.
    })
  },

  data() {
    return {
      // date: new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24),
      true_date:null,
      date: new Date(),
      dash_watcher:null,
      username:null,
      total:null,
      tableData:null
      //     [{
      //   date: '2016-05-02',
      //   name: '王小虎',
      //   province: '上海',
      //   city: '普陀区',
      //   address: '上海市普陀区金沙江路 1518 弄',
      //   zip: 200333
      // }]
    }
  },
  filters: {
    formatDate:function (value) {
      var date = new Date(value);
      var year = date.getFullYear();
      var month = padDate(date.getMonth()+1);
      var day = padDate(date.getDate());
      var hours = padDate(date.getHours());
      var minutes = padDate(date.getMinutes());
      var seconds = padDate(date.getSeconds());
      //var week = padDate(date.getDay());
      let week = new Date(value).getDay();
      let weeks = ["日","一","二","三","四","五","六"];
      let getWeek = "星期" + weeks[week];
      //return year + '-' + month + '-' + day +' '+'|' + ' ' + hours + ':' + minutes + ':' + seconds + ' ' +getWeek;
      return year + '-' + month + '-' + day +' '+'|'+' '  +getWeek;
    }
  }
}
</script>

<style scoped>

</style>